<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="896" @ok="handleSubmit">
      <BasicForm @register="registerForm"/>
  </BasicModal>
</template>

<script lang="ts" setup>
    import {ref, computed, unref} from 'vue';
    import {BasicModal, useModalInner} from '/@/components/Modal';
    import {BasicForm, FormSchema, useForm} from '/@/components/Form/index';
    import {autoSchedule, saveOrUpdate} from '../AttSchedule.api';
    // Emits声明
    const emit = defineEmits(['register','success']);
    const isUpdate = ref(true);
    const setworkdate = ref();
    const formSchema: FormSchema[] = [{
      label: '部门',
      field: 'departmentId',
      component: 'JSelectDept',
      componentProps: ({formModel}) => {
        return {
          checkStrictly: true,
          multiple: false,
        }
      },
      dynamicRules: ({model,schema}) => {
        return [
          { required: true, message: '请选择部门!'},
        ];
      },
    },
      {
        label: '截止日期',
        field: 'workDate',
        component: 'DatePicker',
        dynamicRules: ({model,schema}) => {
          return [
            { required: true, message: '请输入日期!'},
          ];
        },
      }, ];
    //表单配置
    const [registerForm, {setProps,resetFields, setFieldsValue, validate}] = useForm({
        labelWidth: 150,
        schemas: formSchema,
        showActionButtonGroup: false,
        baseColProps: {span: 24}
    });
    //表单赋值
    const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
      setworkdate.value = data.setworkdate;
    });
    //设置标题
    const title = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
    //表单提交事件
    async function handleSubmit(v) {


        try {
            let values = await validate();
          //setworkdate.value(values.workDate)
            setModalProps({confirmLoading: true});
            console.log(values)
            //提交表单
          let res = await autoSchedule(values);
            //关闭弹窗
            closeModal();
            //刷新列表
            emit('success');
        } finally {
            setModalProps({confirmLoading: false});
        }
    }
</script>

<style lang="less" scoped>
	/** 时间和数字输入框样式 */
  :deep(.ant-input-number){
		width: 100%
	}

	:deep(.ant-calendar-picker){
		width: 100%
	}
</style>
